{##
 # Contains macros for trace.
 #
 # @copyright  Copyright (c) 2010-2011 The Fajr authors (see AUTHORS).
 #             Use of this source code is governed by a MIT license that can be
 #             found in the LICENSE file in the project root directory.
 # @author     TODO
 #}

{##
 # TODO: document
 #}
{% macro tooltip(info) %}
  <div class="trace_s">{{ "%+0.2f" |format(info.elapsedTime) }}s
    <div class="trace_tooltip">Function {{ info.class }}::{{ info.function }}()<br />
      Line:&nbsp;{{ info.line }}<br />
      File:&nbsp;{{ info.file }}<br />
      <br />
      Code snippet:
      <pre>{{ info.snippet }}</pre>
    </div>
  </div>
{% endmacro %}

{##
 # TODO: document
 #}
{% macro traceItem(item, content) %}
<div class="trace">
  {{ _self.tooltip(item.info) }}
  {{ content }}
</div>
{% endmacro %}

{##
 # TODO: document
 #}
{% macro traceDataContent(value) %}
  <pre>{{ value }}</pre>
{% endmacro%}

{##
 # TODO: document
 #}
{% macro traceVariableContent(name, value) %}
  ${{ name }}:= <pre class="trace">{{ value }}</pre>
{% endmacro %}

{##
 # TODO: document
 #}
{% macro trace(trace) %}
  {% set content %}
    <div>
      {% for child in trace.children %}
        {% if child.type == "log" %}
          {{ _self.traceItem(child, child.data) }}
        {% elseif child.type == "data" %}
          {{ _self.traceItem(child, _self.traceDataContent(child.data)) }}
        {% elseif child.type == "variable" %}
          {{ _self.traceItem(child, _self.traceVariableContent(child.name, child.data)) }}
        {% elseif child.type == "trace" %}
          {{ _self.traceItem(child, _self.trace(child.trace)) }}
        {% endif %}
      {% endfor %}
    </div>
  {% endset %}
  {% import "macros/decorators.xhtml" as decorators %}
  {{ decorators.collapsible(trace.header, content, true) }}
{% endmacro %}
